package com.gzk.oeno.business.opinion;

import java.util.Date;
import java.util.Map;

import com.gzk.oeno.business.IFriendlyNamed;
import com.gzk.oeno.business.critere.Critere;
import com.gzk.oeno.business.utilisateur.Utilisateur;
import com.gzk.oeno.business.vin.Vin;
import com.gzk.oeno.tech.ui.Formator;
import com.gzk.utils.data.IdObject;

public class Opinion implements IdObject<Integer>, IFriendlyNamed{

	private Integer id;
	private Vin vin;
	private Utilisateur gouteur;
	private Integer score;
	private Date date;
	private String commentaire;
	
	private Map<Critere, String> avis;
	
	
	@Override
	public Integer getId() {
		return id;
	}

	@Override
	public void setId(Integer key) {
		this.id = key;
	}

	public Vin getVin() {
		return vin;
	}

	public void setVin(Vin vin) {
		this.vin = vin;
	}

	public Utilisateur getGouteur() {
		return gouteur;
	}

	public void setGouteur(Utilisateur gouteur) {
		this.gouteur = gouteur;
	}

	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getCommentaire() {
		return commentaire;
	}

	public void setCommentaire(String commentaire) {
		this.commentaire = commentaire;
	}

	public Map<Critere, String> getAvis() {
		return avis;
	}

	public void setAvis(Map<Critere, String> avis) {
		this.avis = avis;
	}

	public boolean hasDetails(){
		return avis != null && !avis.isEmpty();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Opinion other = (Opinion) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String getFriendlyName() {
		StringBuilder sb = new StringBuilder("Opinion de ");
		sb	.append(gouteur.getName())
			.append(" sur ")
			.append(vin.getFriendlyName())
			.append(" (le ")
			.append(Formator.getDateFormat().format(date))
			.append(")");
		return sb.toString();
	}
	
	
	
}
